//
//  ViewController.swift
//  ZipTools
//
//  Created by 齐庆斌 on 2018/4/12.
//  Copyright © 2018年 齐庆斌. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.pathStr.delegate = self
        self.pathStr.returnKeyType = .done
        
    }
    
   
    @IBOutlet weak var pathStr: UITextField!
    
    // 压缩文件
    @IBAction func goToZip(_ sender: Any) {
        self.navigationController?.pushViewController(QQZipViewController(), animated: true)
    }
    
    // 解压文件
    @IBAction func goToUnzip(_ sender: Any) {
//        self.navigationController?.pushViewController(QQUnZipViewController(), animated: true)
        let name = pathStr.text
//        let dir = FileTool.directionIsExistWithDirName(name: name!)
//        if dir.1 {
//            print("path = \(dir.0)")
//        }else {
//            print("is not exist")
//        }
        if name == "" {
            print("is empty")
            return
        }
        let dir = FileTool.copeDir("your", name!)
        if dir.1 {
            print("path = \(dir.0)")
        }else {
            print("move failed")
        }
        
        
    }
    
    

    
    @IBAction func startUnZip(_ sender: Any) {
        print("开始解压缩")
        let destinationPath = NSHomeDirectory() + "/Documents"
        
        if ZipTool.archiveZip(sourcePath:"/Users/qiqingbin/Documents/超级app/ZipTools/ZipTools/20180102.png.zip", destinationPath: destinationPath) {
            print("success")
            print("path = \(destinationPath)")
        }else {
            print("failed")
        }
    }
    
    @IBAction func startZip(_ sender: Any) {
        print("开始压缩")
        let file1 = Bundle.main.path(forResource: "01", ofType: "png")!
        let file2 = Bundle.main.path(forResource: "02", ofType: "png")!
        let path = NSTemporaryDirectory() + "/password.zip"
        if ZipTool.zipFilesWithpassword(files: [file1, file2], path: path, password: "123") {
            print("压缩成功")
            print("path = \(NSTemporaryDirectory())")
        } else {
            print("压缩失败")
        }
    }
}

extension ViewController: UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    
}






